package com.noah.common.redis.utility;

import org.redisson.api.RedissonReactiveClient;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeUnit;

/**
 * @author noah
 * 2023/9/7 19:15
 */
public class RedisReactiveUtility {
    private final RedissonReactiveClient redissonReactiveClient;

    public RedisReactiveUtility(RedissonReactiveClient redissonReactiveClient) {
        this.redissonReactiveClient = redissonReactiveClient;
    }

    public Mono<Object> get(String key) {
        return this.redissonReactiveClient.getBucket(key).get();
    }

    public Mono<Void> set(
            String key, Object object, long expire
    ) {
        return this.redissonReactiveClient.getBucket(key).set(object, expire, TimeUnit.SECONDS);
    }

    public Mono<Long> delete(String key) {
        return this.redissonReactiveClient.getKeys().delete(key);
    }
}
